{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}
<div id="select-stack" class="wizard-content col-md-9" {{QAAttr "select-stack-page"}}>
  <h4 class="step-title">{{t installer.step1.header}}</h4>
  <p class="step-description">{{t installer.step1.body}}</p>

  <div class="panel panel-default">
    <div class="panel-body">
      {{#if isLoadingComplete}}
        {{! left tabs }}
        <div class="tabs-menu">
          <ul class="nav nav-tabs" {{QAAttr "stack-tabs"}}>
            {{#each stack in availableStackTypes}}
              <li {{bindAttr class="stack.isSelected:active"}} {{QAAttr "stack-tab"}}>
                <a {{QAAttr "stack-link-{stack.stackName}"}} {{action "selectRepoInList" stack target="controller"}}
                  href="#">{{stack.stackName}}</a></li>
            {{/each}}
          </ul>
        </div>
        <div class="stacks-options">
          <div class="details-panel">
            <div class="btn-group" {{QAAttr "select-version"}}>
              <button type="button" data-toggle="dropdown"
                      class="btn dropdown-toggle btn-default" {{QAAttr "select-version-button"}}>{{controller.selectedStack.displayName}}
                <span class="caret"></span></button>
              <ul class="dropdown-menu">
                {{#each stack in selectedStackType.stacks}}
                  <li>
                    {{!view view.stackRadioButton stackBinding="stack"}}
                    <a
                      href="#" {{action "changeVersion" stack target="controller"}} {{QAAttr "{stack.displayName}"}}>{{stack.displayName}}
                      {{#if stack.stackDefault}}
                        ({{t installer.step1.changeVersion.defaultVersion}})
                      {{/if}}
                    </a>
                  </li>
                {{/each}}
                <li><a
                  href="#" {{action "uploadVdf" target="controller"}} {{QAAttr "add-new-version"}}>{{t installer.step1.addVersion}}
                  ...</a></li>
              </ul>
            </div>
            <div class="version-contents-section">
              {{#unless servicesForSelectedStack}}
                <div class="alert alert-info"
                     role="alert">{{t installer.step1.useLocalRepo.infoForm.content.empty}}</div>
              {{/unless}}
              <table class="table table-hover">
                <tbody>
                {{#each service in servicesForSelectedStack}}
                  <tr>
                    <td class="col-md-4">{{service.displayName}}</td>
                    <td class="col-md-8">{{service.latestVersion}}</td>
                  </tr>
                {{/each}}
                </tbody>
              </table>
            </div>
          </div>
        </div>
        {{! left tabs end }}

        {{#if App.router.nextBtnClickInProgress}}
          {{view App.SpinnerView}}
        {{else}}
          <form autocomplete="off" id="repoVersionInfoForm" class="form-horizontal" role="form" name="localVersionInfoForm" novalidate>

            <div class="panel panel-default repos-panel">
              <div class="step-title">
                <p>{{t common.repositories}}</p>
              </div>
              <p class="step-description">{{t installer.step1.repo.body}}</p>
              <div class="panel-body version-contents-body">
                <div class="row radio-group">
                  {{! Public Repository radio }}
                  <div {{bindAttr class=":col-sm-4 :radio :big-radio :public-radio :wizard-plain-text"}}>
                    {{view view.usePublicRepoRadioButton classNames="display-inline-block" labelIdentifier="use-public-repo"}}
                    {{#if stackRepoUpdateLinkExists}}
                      {{#if networkIssuesExist}}
                        <a id="public-disabled-link"
                           class="display-inline-block" {{action "openPublicOptionDisabledWindow" target="view"}}>{{t installer.step1.selectUseRepoOptions.public.networkLost}}</a>
                      {{/if}}
                    {{/if}}
                  </div>
                  {{!--Local repo radio--}}
                  {{view view.useLocalRepoRadioButton classNames="radio big-radio col-sm-4" labelIdentifier="use-local-repo"}}
                </div>
                <div class="alert alert-info"
                     role="alert">{{t installer.step1.useLocalRepo.infoForm.alert.baseUrl}}</div>
                {{#if view.showWarning}}
                  <div
                    class="alert alert-warning" {{QAAttr "step1-warning"}}>{{t installer.step1.attentionNeeded}}</div>
                {{/if}}

                {{! OSes and Repositories }}
                <div class="row">
                  <div class="table-controls row col-sm-12 pull-right">
                    <div class="col-sm-12">
                      {{! Add OS }}
                      <div class="btn-group pull-right">
                        <button
                          type="button" {{bindAttr data-original-title="view.addOsButtonTooltip" class=":btn :btn-default :dropdown-toggle :add-os-button view.isAddOsButtonDisabled:disabled"}}
                          {{QAAttr "add-os-button"}}
                          data-toggle="dropdown">
                          <i class="glyphicon glyphicon-plus"></i> {{t common.add}} &nbsp;<span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu">
                          {{#each operatingSystem in selectedStack.operatingSystems}}
                            {{#unless operatingSystem.isSelected}}
                              <li>
                                <a {{action "addOS" operatingSystem target="controller"}} {{QAAttr "add-os-{operatingSystem.osType}"}}>{{operatingSystem.osType}}</a>
                              </li>
                            {{/unless}}
                          {{/each}}
                        </ul>
                      </div>
                      {{! Add OS END}}
                    </div>
                  </div>
                </div>
                <table class="table table-hover">
                  <thead>
                  <tr>
                    <th class="col-sm-2">{{t common.os}}</th>
                    <th class="col-sm-3">{{t common.name}}</th>
                    <th class="col-sm-6">{{t installer.step1.advancedRepo.localRepo.column.baseUrl}}</th>
                    <th class="col-sm-1"></th>
                  </tr>
                  </thead>
                  <tbody>
                  {{#each operatingSystem in selectedStack.operatingSystems}}
                    {{#if operatingSystem.isSelected}}
                      <tr {{QAAttr "os-wrapper"}}>
                        <td class="col-sm-2" {{QAAttr "os-type-label"}}>{{operatingSystem.osType}}</td>
                        <td class="col-sm-9" colspan="2">
                          <table
                            class="table table-condensed no-borders inner-table" {{QAAttr "{operatingSystem.osType}"}}>
                            <tbody>
                            {{#each repository in operatingSystem.repositories}}
                              {{#if repository.showRepo}}
                                <tr {{QAAttr "{repository.repoName}"}}>
                                  <td class="col-sm-3">
                                    {{view view.editableRepoView repositoryBinding="repository"}}
                                  </td>
                                  <td class="col-sm-1">
                                    {{view view.popoverView repositoryBinding="repository" data-qaBinding="repository.validation"}}
                                  </td>
                                  <td class="col-sm-8">
                                    <div {{bindAttr class=":repo-url repository.invalidFormatError:has-error repository.invalidError:has-error"}}>
                                      {{view view.repositoryTextField repositoryBinding="repository" disabledBinding="controller.selectedStack.useRedhatSatellite"}}
                                      {{#if controller.selectedStack.usePublicRepo}}
                                        <i {{bindAttr class="repository.undo::invisible :icon-undo"}}
                                          {{action "doRestoreDefaultValue" repository target="controller"}}
                                          {{translateAttr title="common.undo"}}
                                          {{QAAttr "undo-icon"}}>
                                        </i>
                                      {{else}}
                                        <i {{bindAttr class="repository.notEmpty::invisible :icon-undo"}}
                                          {{action "doRestoreToEmpty" repository target="controller"}}
                                          {{translateAttr title="common.undo"}}
                                          {{QAAttr "undo-icon"}}>
                                        </i>
                                      {{/if}}
                                    </div>
                                  </td>
                                </tr>
                              {{/if}}
                            {{/each}}
                            </tbody>
                          </table>
                        </td>
                        <td class="col-sm-1">
                          <a {{bindAttr class="controller.selectedStack.useRedhatSatellite:disabled :action :remove-icon"}}
                             href="#" {{action "removeOS" operatingSystem target="view"}} {{QAAttr "remove-icon"}}>
                            <span class="icon icon-minus"></span>
                            {{t common.remove}}
                          </a>
                        </td>
                      </tr>
                    {{/if}}
                  {{/each}}
                  </tbody>
                </table>
                {{! OSes and Repositories END }}

                {{! Skip Repository Base URL validation }}
                <div id="skip-validation" {{bindAttr class="controller.selectedStack.useRedhatSatellite:disabled"}}>
                  {{#view App.CheckboxView
                  labelTranslate="installer.step1.advancedRepo.skipValidation.message"
                  labelClassNamesBinding="controller.selectedStack.useRedhatSatellite:disabled"
                  checkedBinding="skipValidationChecked"
                  disabledBinding="controller.selectedStack.useRedhatSatellite"
                  labelIdentifier="skip-validation"
                  }}
                    <i class="glyphicon glyphicon-question-sign" rel="skip-validation-tooltip"
                       data-toggle="tooltip" {{translateAttr data-original-title="installer.step1.advancedRepo.skipValidation.tooltip"}}>
                    </i>
                  {{/view}}
                  <div class="clearfix"></div>
                </div>
                {{! Skip Repository Base URL validation END }}

                {{! Use RedHat Satellite/Spacewalk }}
                <div id="use-redhat">
                  {{#view view.redhatCheckBoxView
                  classNames="use-redhat-checkbox"
                  labelTranslate="installer.step1.advancedRepo.useRedhatSatellite.message"
                  labelClassNamesBinding="controller.selectedStack.usePublicRepo:disabled"
                  }}
                    <i class="glyphicon glyphicon-question-sign" rel="use-redhat-tooltip"
                       data-toggle="tooltip" {{translateAttr data-original-title="installer.step1.advancedRepo.useRedhatSatellite.tooltip"}}>
                    </i>
                  {{/view}}
                </div>
                {{! Use RedHat Satellite/Spacewalk END }}
              </div>
            </div>
          </form>
        {{/if}}
        {{#if view.invalidUrlExist}}
          <div class="alert alert-warning">
            {{t installer.step1.invalidURLAttention}}
            <a
              href="javascript:void(null)" {{action "retryRepoUrls" target="view"}}>{{t installer.step1.retryRepoUrls}}</a>
          </div>
        {{/if}}
      {{else}}
        {{view App.SpinnerView}}
      {{/if}}
    </div>
  </div>
</div>
<div class="wizard-footer col-md-12">
  <button type="button" class="btn btn-default pull-left installer-back-btn" {{bindAttr disabled="App.router.btnClickInProgress"}} {{action back}} {{QAAttr "wizard-back"}}>
    &larr; {{t common.back}}
    {{#if App.router.backBtnClickInProgress}}
      {{view App.SpinnerView tagName="span" classNames="service-button-spinner"}}
    {{/if}}
  </button>
  {{template "templates/wizard/installer_cancel_button"}}
  <button type="button" class="btn btn-success pull-right" {{bindAttr disabled="view.isSubmitDisabled"}} {{action next}} {{QAAttr "wizard-next"}}>
    {{#if App.router.nextBtnClickInProgress}}
      {{view App.SpinnerView tagName="span" classNames="service-button-spinner"}}
    {{/if}}
    {{t common.next}} &rarr;
  </button>
</div>
